import { fire } from "./shooting/fire.js";
import { currentRole, currentState } from "../index.js";
import { scoket } from "../utils/scoket.js";
import { move } from "./move.js";

export const setKey = (key: string) => {
  scheduler[key] || (scheduler[key] = "down");
};
export const removeKey = (key: string) => {
  scheduler[key] && delete scheduler[key];
};

const scheduler: { [key: string]: any } = {};

//指令动作
const actions = () => {
  const keys = Object.keys(scheduler);
  keys.forEach((k) => {
    //判断移动的位置是否是边界
    switch (k) {
      case "a":
      case "d":
      case "w":
      case "s":
        move(k);
        break;
      case "j":
        fire(currentRole);
        break;
    }
  });
  requestAnimationFrame(actions);
};
requestAnimationFrame(actions);
